$(function(){
	
	$("#add-change-input").click(function(){
		if($("#add-change-input")[0].value == "修改成绩"){
			$("#add-change-input")[0].setAttribute("value","保存修改");
			$("*[id^='input-']").each(function(){
				$(this).removeAttr("disabled");
				$(this)[0].style.border="1px solid #ccc";
			});
			
		}else if($("#add-change-input")[0].value == "保存修改"){
			batchUpdateGrade();//会自动刷新界面
			
		}
	});
	/* 显示学生的任务成绩详情 */
	$("#scoreList").delegate("#show-detail-td","click",function(){
		showDetail($(this).children("i"));
	});
	/* 对每个edit-btn的点击事件执行editBtn操作 */
	$("#scoreList").delegate("*[id^='edit-btn-']","click",function(){
		editBtn($(this));
	});
	/* 尝试修改总成绩时提示 */
	$("#scoreList").delegate("*[id='total-score']","click",function(){
		layer.msg("总成绩由其他成绩和对应占比计算生成，只修改总成绩无效！");
	});
	$("#build-score-excel-btn").click(function() {
		$("#build-excel-file-layer").modal("show");
	});
});

var showDetail = function(i){
	var index = i.attr("id").replace(/show-detail-btn-/,"");
	if(i[0].className == "fa fa-chevron-right"){
		i[0].setAttribute("class","fa fa-chevron-down");
		i[0].parentNode.style.backgroundColor="#d8dad6";
		$("*[id$='detail-list-"+index+"']").show();		
		taskScoreLog(index);
	}else if(i[0].className == "fa fa-chevron-down"){
		i[0].setAttribute("class","fa fa-chevron-right");
		i[0].parentNode.style.backgroundColor="transparent";
		$("*[id$='detail-list-"+index+"']").hide();
	}
}

var editBtn = function(btn){
	/*获取编辑按钮的尾部序号*/
	var index = btn.attr("id").replace(/edit-btn-/,"");
	//index表示对应的table's row
	
	if(btn[0].value == "编辑"){
		btn.attr("value","保存");
		btn[0].style.background='#f0ad4e';
		$("*[id$='-score-"+index+"']").each(function(){
			$(this).removeAttr("disabled");
			$(this)[0].style.border="1px solid #ccc";
		});
	}else{
		updateGrade(index);//会自动刷新界面		
	}
}